﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Limilabs.Mail;
using Limilabs.Mail.Headers;
using Limilabs.Client.SMTP;


namespace PennApps
{
    public partial class TransportService
    {
        private static string userNameEmail = "momapp2013@gmail.com";
        private static string password = "liangluo";
        private static string infoDestinationEmail = "momapp2013@gmail.com";
        private static string commandDestinationEmail = "momapp2013commands@gmail.com";

        public static async void Send(ProcessPerformanceInformation[] performanceInfoArray)
        {
            MailBuilder builder = new MailBuilder();
            builder.From.Add(new MailBox(userNameEmail));
            builder.To.Add(new MailBox(infoDestinationEmail));
            builder.Subject = "INFO";
            builder.Text = (new PerformanceInfoToTextConversionEngine()).Convert(performanceInfoArray);
            IMail email = builder.Create();
            // Send the message
            using (Smtp smtp = new Smtp())
            {
                await smtp.ConnectSSL("smtp.gmail.com", 465);    // or ConnectSSL for SSL
                await smtp.UseBestLoginAsync(userNameEmail, password); // remove if not needed
                await smtp.SendMessageAsync(email);
                await smtp.CloseAsync();
            }

        }

        public static async void sendCommand(Command command)
        {
            PerformanceInfoToTextConversionEngine converter = new PerformanceInfoToTextConversionEngine();
            string commandText = converter.CommandConvertBack(command);
            MailBuilder builder = new MailBuilder();
            builder.From.Add(new MailBox(userNameEmail));
            builder.To.Add(new MailBox(commandDestinationEmail));
            builder.Subject = "COMMAND";
            builder.Text = commandText;
            IMail email = builder.Create();
            // Send the message
            using (Smtp smtp = new Smtp())
            {
                await smtp.ConnectSSL("smtp.gmail.com", 465);    // or ConnectSSL for SSL
                await smtp.UseBestLoginAsync(userNameEmail, password); // remove if not needed
                await smtp.SendMessageAsync(email);
                await smtp.CloseAsync();
            }

        }



    }
}
